# Copyright 2024 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# Thinkit is a set of interfaces to enable PINS testing to be infrastructure agnostic.

package(
    default_visibility = ["//visibility:public"],
    licenses = ["notice"],
)

cc_library(
    name = "thinkit",
    deps = [
        ":control_device",
        ":generic_testbed",
        ":mirror_testbed",
        ":switch",
        ":test_environment",
    ],
)

cc_library(
    name = "thinkit_mocks",
    testonly = 1,
    deps = [
        ":mock_control_device",
        ":mock_generic_testbed",
        ":mock_mirror_testbed",
        ":mock_switch",
        ":mock_test_environment",
    ],
)

cc_library(
    name = "switch",
    hdrs = ["switch.h"],
    deps = [
        "@com_github_gnmi//proto/gnmi:gnmi_cc_grpc_proto",
        "@com_github_gnoi//cert:cert_cc_grpc_proto",
        "@com_github_gnoi//diag:diag_cc_grpc_proto",
        "@com_github_gnoi//factory_reset:factory_reset_cc_grpc_proto",
        "@com_github_gnoi//os:os_cc_grpc_proto",
        "@com_github_gnoi//system:system_cc_grpc_proto",
        "@com_github_grpc_grpc//:grpc++",
        "@com_github_p4lang_p4runtime//:p4runtime_cc_grpc",
        "@com_google_absl//absl/status",
        "@com_google_absl//absl/status:statusor",
    ],
)

cc_test(
    name = "switch_test",
    srcs = ["switch_test.cc"],
    deps = [
        ":switch",
        "//gutil/gutil:status_matchers",
        "@com_github_gnmi//proto/gnmi:gnmi_cc_grpc_proto",
        "@com_github_gnoi//cert:cert_cc_grpc_proto",
        "@com_github_gnoi//diag:diag_cc_grpc_proto",
        "@com_github_gnoi//factory_reset:factory_reset_cc_grpc_proto",
        "@com_github_gnoi//os:os_cc_grpc_proto",
        "@com_github_gnoi//system:system_cc_grpc_proto",
        "@com_github_p4lang_p4runtime//:p4runtime_cc_grpc",
        "@com_google_absl//absl/status",
        "@com_google_googletest//:gtest_main",
    ],
)

cc_library(
    name = "mock_switch",
    testonly = 1,
    hdrs = ["mock_switch.h"],
    deps = [
        ":switch",
        "@com_github_gnmi//proto/gnmi:gnmi_cc_grpc_proto",
        "@com_github_gnoi//cert:cert_cc_grpc_proto",
        "@com_github_gnoi//diag:diag_cc_grpc_proto",
        "@com_github_gnoi//factory_reset:factory_reset_cc_grpc_proto",
        "@com_github_gnoi//os:os_cc_grpc_proto",
        "@com_github_gnoi//system:system_cc_grpc_proto",
        "@com_github_p4lang_p4runtime//:p4runtime_cc_grpc",
        "@com_google_absl//absl/status:statusor",
        "@com_google_googletest//:gtest",
    ],
)

cc_test(
    name = "mock_switch_test",
    srcs = ["mock_switch_test.cc"],
    deps = [
        ":mock_switch",
        "@com_google_googletest//:gtest_main",
    ],
)

cc_library(
    name = "mirror_testbed",
    hdrs = ["mirror_testbed.h"],
    deps = [
        ":switch",
        ":test_environment",
    ],
)

cc_library(
    name = "mirror_testbed_fixture",
    testonly = 1,
    hdrs = ["mirror_testbed_fixture.h"],
    deps = [
        ":mirror_testbed",
        "@com_github_p4lang_p4runtime//:p4info_cc_proto",
        "@com_google_absl//absl/memory",
        "@com_google_absl//absl/status",
        "@com_google_absl//absl/strings",
        "@com_google_googletest//:gtest",
    ],
)

cc_library(
    name = "mock_mirror_testbed",
    testonly = 1,
    hdrs = ["mock_mirror_testbed.h"],
    deps = [
        ":mirror_testbed",
        ":switch",
        ":test_environment",
        "@com_google_googletest//:gtest",
    ],
)

cc_test(
    name = "mock_mirror_testbed_test",
    srcs = ["mock_mirror_testbed_test.cc"],
    deps = [
        ":mock_mirror_testbed",
        "@com_google_googletest//:gtest_main",
    ],
)

cc_library(
    name = "test_environment",
    hdrs = ["test_environment.h"],
    deps = [
        "//thinkit/proto:metrics_cc_proto",
        "@com_google_absl//absl/status",
        "@com_google_absl//absl/strings",
        "@com_google_protobuf//:protobuf",
    ],
)

cc_library(
    name = "mock_test_environment",
    testonly = 1,
    hdrs = ["mock_test_environment.h"],
    deps = [
        ":test_environment",
        "//thinkit/proto:metrics_cc_proto",
        "@com_google_absl//absl/status",
        "@com_google_absl//absl/strings",
        "@com_google_googletest//:gtest",
    ],
)

cc_test(
    name = "mock_test_environment_test",
    srcs = ["mock_test_environment_test.cc"],
    deps = [
        ":mock_test_environment",
        "@com_google_googletest//:gtest_main",
    ],
)

cc_library(
    name = "bazel_test_environment",
    testonly = True,
    srcs = ["bazel_test_environment.cc"],
    hdrs = ["bazel_test_environment.h"],
    deps = [
        ":test_environment",
        "//gutil/gutil:test_artifact_writer",
        "@com_google_absl//absl/base:core_headers",
        "@com_google_absl//absl/container:flat_hash_map",
        "@com_google_absl//absl/status",
        "@com_google_absl//absl/strings",
        "@com_google_absl//absl/synchronization",
    ],
)

cc_test(
    name = "bazel_test_environment_test",
    srcs = ["bazel_test_environment_test.cc"],
    deps = [
        ":bazel_test_environment",
        ":test_environment",
        "@com_google_protobuf//:protobuf",
        "@com_google_googletest//:gtest_main",
        "@com_google_absl//absl/memory",
        "@com_google_absl//absl/strings",
        # This dependency is not technically needed inside Google3,
        # but is a hack to keep the Copybara rules simple.
        "@com_google_benchmark//:benchmark",
        "//gutil/gutil:status_matchers",
        "//gutil/gutil:testing",
    ],
)

cc_library(
    name = "ssh_client",
    hdrs = ["ssh_client.h"],
    deps = [
        "@com_google_absl//absl/status",
        "@com_google_absl//absl/status:statusor",
        "@com_google_absl//absl/strings",
        "@com_google_absl//absl/time",
    ],
)

cc_library(
    name = "mock_ssh_client",
    testonly = 1,
    hdrs = ["mock_ssh_client.h"],
    deps = [
        ":ssh_client",
        "@com_google_absl//absl/status",
        "@com_google_absl//absl/status:statusor",
        "@com_google_absl//absl/strings",
        "@com_google_absl//absl/time",
        "@com_google_googletest//:gtest",
    ],
)

cc_test(
    name = "mock_ssh_client_test",
    srcs = ["mock_ssh_client_test.cc"],
    deps = [
        ":mock_ssh_client",
        "@com_google_googletest//:gtest_main",
    ],
)

cc_library(
    name = "generic_testbed",
    hdrs = ["generic_testbed.h"],
    deps = [
        ":control_device",
        ":switch",
        ":test_environment",
        "//thinkit/proto:generic_testbed_cc_proto",
        "@com_github_otg_models//:otg_grpc_proto",
        "@com_google_absl//absl/container:flat_hash_map",
        "@com_google_absl//absl/container:flat_hash_set",
        "@com_google_absl//absl/status:statusor",
        "@com_google_absl//absl/strings",
    ],
)

cc_library(
    name = "generic_testbed_fixture",
    testonly = 1,
    hdrs = ["generic_testbed_fixture.h"],
    deps = [
        ":generic_testbed",
        "//thinkit/proto:generic_testbed_cc_proto",
        "@com_github_p4lang_p4runtime//:p4info_cc_proto",
        "@com_google_absl//absl/memory",
        "@com_google_absl//absl/status:statusor",
        "@com_google_googletest//:gtest",
    ],
)

cc_library(
    name = "mock_generic_testbed",
    testonly = 1,
    hdrs = ["mock_generic_testbed.h"],
    deps = [
        ":control_device",
        ":generic_testbed",
        ":switch",
        ":test_environment",
        "@com_google_absl//absl/status:statusor",
        "@com_google_absl//absl/strings",
        "@com_google_googletest//:gtest",
    ],
)

cc_test(
    name = "mock_generic_testbed_test",
    srcs = ["mock_generic_testbed_test.cc"],
    deps = [
        ":mock_generic_testbed",
        "@com_google_googletest//:gtest_main",
    ],
)

cc_library(
    name = "control_device",
    hdrs = ["control_device.h"],
    deps = [
        ":packet_generation_finalizer",
        "@com_github_gnoi//diag:diag_cc_proto",
        "@com_github_grpc_grpc//:grpc++",
        "@com_google_absl//absl/base:core_headers",
        "@com_google_absl//absl/container:flat_hash_map",
        "@com_google_absl//absl/container:flat_hash_set",
        "@com_google_absl//absl/status",
        "@com_google_absl//absl/status:statusor",
        "@com_google_absl//absl/strings",
        "@com_google_absl//absl/time",
        "@com_google_absl//absl/types:span",
    ],
)

cc_library(
    name = "mock_control_device",
    testonly = 1,
    hdrs = ["mock_control_device.h"],
    deps = [
        ":control_device",
        ":packet_generation_finalizer",
        "@com_github_gnoi//diag:diag_cc_proto",
        "@com_google_absl//absl/container:flat_hash_map",
        "@com_google_absl//absl/container:flat_hash_set",
        "@com_google_absl//absl/status",
        "@com_google_absl//absl/status:statusor",
        "@com_google_absl//absl/strings",
        "@com_google_absl//absl/time",
        "@com_google_absl//absl/types:span",
        "@com_google_googletest//:gtest",
    ],
)

cc_test(
    name = "mock_control_device_test",
    srcs = ["mock_control_device_test.cc"],
    deps = [
        ":mock_control_device",
        "@com_google_googletest//:gtest_main",
    ],
)

cc_test(
    name = "generic_testbed_test",
    srcs = ["generic_testbed_test.cc"],
    deps = [
        ":generic_testbed",
        "@com_google_googletest//:gtest_main",
    ],
)

cc_library(
    name = "packet_generation_finalizer",
    hdrs = ["packet_generation_finalizer.h"],
    deps = [
        "@com_google_absl//absl/status",
        "@com_google_absl//absl/time",
    ],
)
